package com.neusoft.bo;


import com.neusoft.po.VirtualWalletTransaction;
import com.neusoft.util.CommonUtil;


public class VirtualWalletBO {
	private Integer walletId;
	private String userId;//钱包对应所属用户
	private String createTime;
	private Double balance;
	
	//service层业务方法封装
//	@Autowired
//	VirtualWalletMapper virtualWalletMapper;
//	@Autowired
//	VirtualWalletTransactionMapper transactionMapper;
	//充值
	public VirtualWalletTransaction recharge(Double addAmount) {
		//1.增加金额
		this.balance+=addAmount;
		//2.创建交易流水
		VirtualWalletTransaction transaction = new VirtualWalletTransaction();
		transaction.setTime(CommonUtil.getCurrentDate());
		transaction.setAmount(addAmount);
		transaction.setTransactionType(1);
		transaction.setInWalletId(this.walletId);
//		//3.持久化
//		transactionMapper.saveTransaction(transaction);
		//把对象返回给service做持久化
		return transaction;
	}
	
		//支付
		public VirtualWalletTransaction payment(Double paymentAmount) {
			//1.减少金额
			this.balance-=paymentAmount;
			//2.创建交易流水
			VirtualWalletTransaction transaction = new VirtualWalletTransaction();
			transaction.setTime(CommonUtil.getCurrentDate());
			transaction.setAmount(paymentAmount);
			transaction.setTransactionType(3);
			//transaction.setInWalletId(inId);
			//支付没有入账钱包
			transaction.setOutWalletId(this.walletId);
			return transaction;
		}
		
		//提现
		public VirtualWalletTransaction withdraw(Double withdrawAmount) {
			//1.减少金额
			this.balance-=withdrawAmount;
			//2.创建交易流水
			VirtualWalletTransaction transaction = new VirtualWalletTransaction();
			transaction.setTime(CommonUtil.getCurrentDate());
			transaction.setAmount(withdrawAmount);
			transaction.setTransactionType(2);
			transaction.setOutWalletId(this.walletId);
			return transaction;
		}
	
//	//支持方法
//	public void addBalance(Double addAmount) {
//		this.balance+=addAmount;
//	}
	
	//getter,setter
	public Integer getWalletId() {
		return walletId;
	}
	public void setWalletId(Integer walletId) {
		this.walletId = walletId;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	public Double getBalance() {
		return balance;
	}
	public void setBalance(Double balance) {
		this.balance = balance;
	}
	
	
}
